home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kgame / kgamedialogconfig.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  10.3 KB  |  363 lines

  1. /*
  2.     This file is part of the KDE games library
  3.     Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
  4.     Copyright (C) 2001 Martin Heni (martin@heni-online.de)
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License version 2 as published by the Free Software Foundation.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public License
  16.     along with this library; see the file COPYING.LIB.  If not, write to
  17.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.     Boston, MA 02110-1301, USA.
  19. */
  20.  
  21. // NAMING
  22. // please follow these naming rules if you add/change classes:
  23. // the main dialog is named KGameDialog and the base config widget
  24. // KGameDialogConfig. All config widgets are named KGameDialogXYZConfig (where
  25. // XYZ = the name of the config widget, like "general" or "network") and are
  26. // inherited from KGameDialogConfig.
  27.  
  28. #ifndef __KGAMEDIALOGCONFIG_H__
  29. #define __KGAMEDIALOGCONFIG_H__
  30.  
  31. #include <qwidget.h>
  32. #include <kdemacros.h>
  33.  
  34. class QGridLayout;
  35. class QVBoxLayout;
  36. class QListBoxItem;
  37.  
  38. class KGame;
  39. class KPlayer;
  40. class KGamePropertyBase;
  41.  
  42. class KGameDialogConfigPrivate;
  43. /**
  44.  * Base class for configuration widgets.
  45.  *
  46.  * You can inherit from this and implement @ref submitToKGame, @ref
  47.  * setOwner and @ref setKGame to create your personal @ref KGame configuration widget :-)
  48.  * @short Base class for configuration widgets
  49.  * @author Andreas Beckermann <b_mann@gmx.de>
  50.  **/
  51. class KDE_EXPORT KGameDialogConfig : public QWidget
  52. {
  53.     Q_OBJECT
  54. public:
  55.     KGameDialogConfig(QWidget* parent = 0);
  56.     virtual ~KGameDialogConfig();
  57.  
  58.     /**
  59.      * Called by @ref KGameDialog to submit all settings to the KGame
  60.      * Object.
  61.      * You have to replace this if you add your own widgets!
  62.      * @param g A pointer to your KGame.
  63.      * @param p A pointer to the player owning this dialog
  64.      **/
  65.     virtual void submitToKGame(KGame* g, KPlayer* p) = 0;
  66.  
  67.     /**
  68.      * The owner player of the dialog has been changed. The default
  69.      * changes the pointer for owner so don't forget to call the
  70.      * default implementation if you overwrite this!
  71.      *
  72.      * You can use this e.g. to change a line edit widget containing the 
  73.      * player name.
  74.      *
  75.      * Note: even NULL players are allowed!
  76.      * @param p The new owner player of the dialog
  77.      **/
  78.     virtual void setOwner(KPlayer* p);
  79.  
  80.     /**
  81.      * The KGame object of the dialog has been changed. The default
  82.      * implementation changes the pointer for game so don't forget to
  83.      * call the default implementation if you overwrite this!
  84.      *
  85.      * You can use this e.g. to re-read the min/max player settings.
  86.      * @param g The KGame object
  87.      **/
  88.     virtual void setKGame(KGame* g);
  89.  
  90.     /**
  91.      * The admin status has been changed.
  92.      * If the KGame object of this config widget is the
  93.      * admin the user is allowed to configure it. Otherwise most
  94.      * widgets will have to be disabled. Note that you don't necessarily
  95.      * need to deactivate all widget - e.g. the player name must be
  96.      * configured by the player. Mainly the KGame configuration can be done
  97.      * by the admin only.
  98.      *
  99.      * By default this does nothing. Changes the value for admin so 
  100.      * don't forget to call the default implementation in derived classes!
  101.      * @param admin Whether the KGame object of this dialog can be
  102.      * configured
  103.      **/
  104.     virtual void setAdmin(bool admin);
  105.  
  106.     /**
  107.      * A pointer to the     KGame object that has been set by @ref setKGame.
  108.      *
  109.      * Note that NULL is allowed!
  110.      * @return The KGame object assigned to this dialog
  111.      **/
  112.     KGame* game() const;
  113.  
  114.     /**
  115.      * A pointer to the KPlayer object that has been set by @ref
  116.      * setOwner.
  117.      *
  118.      * Note that NULL is allowed!
  119.      * @return The owner of the dialog
  120.      **/
  121.     KPlayer* owner() const;
  122.  
  123.     /**
  124.      * @return True if the owner is ADMIN otherwise FALSE. See also
  125.      * @ref setAdmin
  126.      **/
  127.     bool admin() const;
  128.  
  129. protected:
  130.  
  131. private:
  132.     KGameDialogConfigPrivate* d;
  133. };
  134.  
  135. /**
  136.  * The main game configuration widget.
  137.  * 
  138.  * It currently contains a line edit for the name of the player only. You can
  139.  * add widgets by using the KGameDialogGeneralConfig as parent parameter as it
  140.  * uses QLayout::autoAdd == true.
  141.  * @author Andreas Beckermann <b_mann@gmx.de>
  142.  **/
  143. class KGameDialogGeneralConfigPrivate;
  144. class KGameDialogGeneralConfig : public KGameDialogConfig
  145. {
  146.     Q_OBJECT
  147. public:
  148.     /**
  149.      * Construct a KGameDialogGeneralConfig. Currently it contains a line
  150.      * edit widget to change the player name only.
  151.      *
  152.      * If you just want to add more widgets you can just create your widgets
  153.      * with the KGameDialogGeneralConfig as parent as it uses
  154.      * QLayout::setAutoAdd(true).
  155.      *
  156.      * @param parent Parent widget for this dialog.
  157.      * @param initializeGUI If you really don't want to use the 
  158.      * predefined widget and/or layout use FALSE here. Note that then none
  159.      * of the predefined widgets (currently only the name of the player) 
  160.      * will exist anymore.
  161.      *
  162.      **/
  163.     KGameDialogGeneralConfig(QWidget* parent = 0, bool initializeGUI = true);
  164.     virtual ~KGameDialogGeneralConfig();
  165.  
  166.     /**
  167.      * Called by @ref KGameDialog to submit all settings to the KGame
  168.      * Object.
  169.      * You have to replace this if you add your own widgets!
  170.      * @param g A pointer to your KGame.
  171.      * @param p A pointer to the player owning this dialog
  172.      **/
  173.     virtual void submitToKGame(KGame* g, KPlayer* p);
  174.  
  175.     /**
  176.      * Change the owner of the config widget.
  177.      *
  178.      * Changes the playername in the line edit
  179.      * @param p The new owner player
  180.      **/
  181.     virtual void setOwner(KPlayer* p);
  182.  
  183.     /**
  184.      * See @ref KGameDialogConfig::setKGame
  185.      *
  186.      * Sets the default values of all KGame related predefined widgets
  187.      * (currently none)
  188.      **/
  189.     virtual void setKGame(KGame* g);
  190.  
  191.     /**
  192.      * See @ref KGameDialogConfig::setAdmin
  193.      *
  194.      * This deactivates the min/max player widgets
  195.      **/
  196.     virtual void setAdmin(bool admin);
  197.  
  198. protected slots:
  199.     void slotPropertyChanged(KGamePropertyBase*, KPlayer*);
  200.  
  201. protected:
  202.     void setPlayerName(const QString& name);
  203.  
  204.     QString playerName() const;
  205.  
  206. private:
  207.     KGameDialogGeneralConfigPrivate* d;
  208. };
  209.  
  210. class KGameDialogNetworkConfigPrivate;
  211. class KDE_EXPORT KGameDialogNetworkConfig : public KGameDialogConfig
  212. {
  213.     Q_OBJECT
  214. public:
  215.     KGameDialogNetworkConfig(QWidget* parent = 0);
  216.     virtual ~KGameDialogNetworkConfig();
  217.  
  218.  
  219.     void disableInitConnection();
  220.  
  221.     /**
  222.      * Called by @ref KGameDialog to submit all settings to the KGame
  223.      * Object.
  224.      * You have to replace this if you add your own widgets!
  225.      * @param g A pointer to your KGame.
  226.      * @param p A pointer to the player owning this dialog
  227.      **/
  228.     virtual void submitToKGame(KGame* g, KPlayer* p);
  229.  
  230.     virtual void setKGame(KGame* g);
  231.  
  232.     /**
  233.      * This sets the default port and host used in @ref KGameConnectDialog.
  234.      * The user will be able to change these defaults!
  235.      *
  236.      * If you don't call this then host "localhost" and port "0" is used.
  237.      * You are strongly encouraged to change at least the port!
  238.      * @param port The default port to connect to / listen on
  239.      * @param host The default host to connect to
  240.      **/
  241.     void setDefaultNetworkInfo(const QString& host, unsigned short int port,bool server=true);
  242.     
  243.     /**
  244.      * Set service type that will be published or browsed for and game name that will be displayed in 
  245.      * server browser. Without this  publishing and discovery of LAN servers will not be enabled.
  246.      * @param name Game name. Important only for server mode. If not
  247.      * set hostname will be used. In case of name conflict -2, -3 and so on will be added to name.
  248.      * @param type Service type (something like _kwin4._tcp). It should be unique for application.
  249.      * @since 3.4
  250.      **/
  251.     void setDiscoveryInfo(const QString& type, const QString& name=QString::null);
  252.     
  253. signals:
  254.   /**
  255.   * This signal is emmited if the user changes the server type (client/server)
  256.   * in the network configuration dialog. 
  257.   *
  258.   * @param t - type type (0/1) of the connection
  259.   **/
  260.   void signalServerTypeChanged(int);
  261.  
  262.  
  263. protected:
  264.     void setConnected(bool connected, bool master = false);
  265.  
  266. protected slots:
  267.     void slotInitConnection();
  268.     void slotExitConnection();
  269.     void slotConnectionBroken();
  270.  
  271.  
  272. private:
  273.     KGameDialogNetworkConfigPrivate* d;
  274. };
  275.  
  276. class KGameDialogMsgServerConfigPrivate;
  277. class KGameDialogMsgServerConfig : public KGameDialogConfig
  278. {
  279.     Q_OBJECT
  280. public:
  281.     KGameDialogMsgServerConfig(QWidget* parent = 0);
  282.     virtual ~KGameDialogMsgServerConfig();
  283.  
  284.     virtual void submitToKGame(KGame*, KPlayer*) {}
  285.  
  286.     void setHasMsgServer(bool);
  287.  
  288.     virtual void setKGame(KGame* g);
  289.     virtual void setAdmin(bool);
  290.  
  291. protected slots:
  292.     void slotChangeMaxClients();
  293.     void slotChangeAdmin();
  294.     void slotRemoveClient();
  295.  
  296. protected:
  297.     void removeClient(Q_UINT32 id);
  298.  
  299. private:
  300.     KGameDialogMsgServerConfigPrivate* d;
  301. };
  302.  
  303. class KGameDialogChatConfigPrivate;
  304. /**
  305.  * This is not really a configuration widget but rather a simple chat widget.
  306.  * This widget does nothing but just providing a @ref KGameChat object.
  307.  * @short A chat widget inside a @ref KGameDialog
  308.  * @author Andreas Beckermann <b_mann@gmx.de>
  309.  **/
  310. class KGameDialogChatConfig : public KGameDialogConfig
  311. {
  312.     Q_OBJECT
  313. public:
  314.     KGameDialogChatConfig(int chatMsgId, QWidget* parent = 0);
  315.     virtual ~KGameDialogChatConfig();
  316.  
  317.     virtual void setKGame(KGame* g);
  318.     virtual void setOwner(KPlayer* p);
  319.  
  320.     virtual void submitToKGame(KGame* g, KPlayer* p) { Q_UNUSED(g); Q_UNUSED(p); }
  321.  
  322. private:
  323.     KGameDialogChatConfigPrivate* d;
  324. };
  325.  
  326. /**
  327.  * @short Lists all connected players and gives the ability to kick them off the
  328.  * game
  329.  **/
  330. class KGameDialogConnectionConfigPrivate;
  331. class KGameDialogConnectionConfig : public KGameDialogConfig
  332. {
  333.     Q_OBJECT
  334. public:
  335.     KGameDialogConnectionConfig(QWidget* parent = 0);
  336.     virtual ~KGameDialogConnectionConfig();
  337.  
  338.     virtual void setKGame(KGame* g);
  339.     virtual void setOwner(KPlayer* p);
  340.     virtual void setAdmin(bool admin);
  341.  
  342.     virtual void submitToKGame(KGame* g, KPlayer* p) { Q_UNUSED(g); Q_UNUSED(p); }
  343.  
  344. protected:
  345.     /**
  346.      * @param p A player
  347.      * @return The QListBoxItem that belongs to the player @p p
  348.      **/
  349.     QListBoxItem* item(KPlayer* p) const;
  350.  
  351. protected slots:
  352.     void slotKickPlayerOut(QListBoxItem* item);
  353.     void slotPropertyChanged(KGamePropertyBase* prop, KPlayer* p);
  354.     void slotPlayerLeftGame(KPlayer* p);
  355.     void slotPlayerJoinedGame(KPlayer* p);
  356.     void slotClearPlayers();
  357.  
  358. private:
  359.     KGameDialogConnectionConfigPrivate* d;
  360.         
  361. };
  362. #endif
  363.